package com.example.zp.liaotian;

import android.content.Context;
import android.content.Intent;
import android.util.Log;

import com.example.zp.entity.PullMessage;
import com.example.zp.sqldata.MySqliteUtlis;
import com.example.zp.utils.FileUtils;
import com.jbm.core.client.MainCallback;
import com.jbm.core.common.ConnectAgent;
import com.jbm.onehome.iface.ICertAddress;

import java.util.Calendar;

/**
 * Created by donar_work on 2017/3/7.
 */

public class TestMsg implements MainCallback {
    Context context;
    public Integer send_id;
    public String Msg;
    private int local_id;
    public int cg_id;
    public String Top;
    private PullMessage pull;
    private FileUtils fileUtils;
    public TestMsg(Context context,int local_id){
        this.context = context;
        this.local_id = local_id;
        //小秘书的消息
         pull=new PullMessage();
        fileUtils=new FileUtils(context);

    }
    @Override
    public void NewAccount(ConnectAgent ca) {//添加新好友

    }

    @Override
    public void RemoveAccount(Integer account_id) {//删除好友

    }

    @Override
    public void UpdateAccount(boolean pullall, ConnectAgent ca) {//更新好友状态

    }

    @Override
    public void OfflineAccount(int status, ConnectAgent ca) {//好友离线状态

    }

    @Override
    public void NewDevice(ConnectAgent ca) {

    }

    @Override
    public void RemoveDevice(Integer account_id) {

    }

    @Override
    public void UpdateDevice(boolean pullall, ConnectAgent ca) {

    }

    @Override
    public void OfflineDevice(ConnectAgent ca) {

    }

    @Override
    public void NewText(Integer account_id, String text) {//接收消息
        send_id = account_id;
        Msg = text;
        MySqliteUtlis.GetInstan(context).StoringChatData(local_id,Msg,send_id,getDate(),String.valueOf(send_id),false,7);
        Intent intent = new Intent();
        intent.setAction("MSG");
        context.sendBroadcast(intent);
        Log.e("MSG:",Msg);

    }

    @Override
    public void GPConfirmStart(int cg_id) {
//        this.cg_id = cg_id;
//        MySqliteUtlis.GetInstan(context).StoringChatData(local_id,"您是否需要维修服务？",cg_id,getDate(),String.valueOf(cg_id),"2");
//        Intent intent  = new Intent();
//        intent.setAction("CG");
//        context.sendBroadcast(intent);
//        Log.e("CG:",String.valueOf(cg_id));

        pull.setCg_id(cg_id);
    }

    @Override
    public void GPSelectCertAddress(int cg_id, ICertAddress[] ca) {
        pull.setCa(ca);
        this.cg_id = cg_id;
//        MySqliteUtlis.GetInstan(context).StoringChatData(local_id,"请选择您的联系地址",cg_id,getDate(),String.valueOf(cg_id),"3");
//        Intent intent  = new Intent();
//        intent.setAction("CGAD");
//        context.sendBroadcast(intent);
//        ArrayList<String> li = MySqliteUtlis.GetInstan(context).showaAddessid();
//        if(li.toString() != null) {
//            for (int i = 0; i < ca.length; i++) {
////                if (!li.toString().contains(String.valueOf(ca[i].caddr_id))) {
//                    MySqliteUtlis.GetInstan(context).StoringAddressData(ca[i].caddr_id, ca[i].contacts, ca[i].gi_text, ca[i].mobile);
////                }
//            }
//        }
    }

    @Override
    public void GPSelectCatalog(int cg_id, String[] catalog) {
        pull.setCatalog(catalog);

    }

    @Override
    public void GPSelectTeam(int cg_id, String[] team) {
        pull.setTeam(team);
        fileUtils.Write(pull);
        Intent intent  = new Intent();
        intent.setAction("CG");
        context.sendBroadcast(intent);


    }

    private String getDate() {
        Calendar c = Calendar.getInstance();

        String year = String.valueOf(c.get(Calendar.YEAR));
        String month = String.valueOf(c.get(Calendar.MONTH));
        String day = String.valueOf(c.get(Calendar.DAY_OF_MONTH) + 1);
        String hour = String.valueOf(c.get(Calendar.HOUR_OF_DAY));
        String mins = String.valueOf(c.get(Calendar.MINUTE));

        StringBuffer sbBuffer = new StringBuffer();
        sbBuffer.append(year + "-" + month + "-" + day + " " + hour + ":"
                + mins);

        return sbBuffer.toString();
    }
}
